<?php

function check_input($value)
{	
	if (get_magic_quotes_gpc())
	{
		$value = stripslashes($value);
	}
	if (!is_numeric($value))
	{
		echo "not number<br>";
		if(function_exists('mysql_real_escape_string'))
		{
			echo "func exits!";
			$value = "'" . mysql_real_escape_string($value) . "'";
		}
		else
		{
				exit("mysql_real_escape_string disabled");
		}
	}
	return $value;
}



class secure
{
/*
    function secureSuperGlobalGET(&$value, $key)
    {
        $_GET[$key] = htmlspecialchars(stripslashes($_GET[$key]));
        $_GET[$key] = str_ireplace("script", "blocked", $_GET[$key]);
        $_GET[$key] = mysql_escape_string($_GET[$key]);
        return $_GET[$key];
    }
   
    function secureSuperGlobalPOST(&$value, $key)
    {
        $_POST[$key] = htmlspecialchars(stripslashes($_POST[$key]));
        $_POST[$key] = str_ireplace("script", "blocked", $_POST[$key]);
        $_POST[$key] = mysql_escape_string($_POST[$key]);
        return $_POST[$key];
    }
*/
    function secureSuperGlobalGET(&$value, $key)
    {
    	if (get_magic_quotes_gpc())
    	{
    		$_GET[$key] = stripslashes($_GET[$key]);
    	}
        $_GET[$key] = htmlspecialchars(stripslashes($_GET[$key]));
        $_GET[$key] = str_ireplace("script", "blocked", $_GET[$key]);
        $_GET[$key] = mysql_escape_string($_GET[$key]);
        return $_GET[$key];
    }
   
    function secureSuperGlobalPOST(&$value, $key)
    {
        $_POST[$key] = htmlspecialchars(stripslashes($_POST[$key]));
        $_POST[$key] = str_ireplace("script", "blocked", $_POST[$key]);
        $_POST[$key] = mysql_escape_string($_POST[$key]);
        return $_POST[$key];
    }
           
    function secureGlobals()
    {
        array_walk($_GET, array($this, 'secureSuperGlobalGET'));
        array_walk($_POST, array($this, 'secureSuperGlobalPOST'));
    }

	/*
		function secGet($value, $key)
    {    
    	$_GET[$key] = "dream";
    	echo $value + $key;
    	//return $_GET[$key];
  	}
	
    function secureGlobals2()
    {
    	array_walk($_GET, "secGet");
    	echo "secureGlobals2";
    }
 */ 
}





$m = new secure();
$m->secureGlobals();


echo check_input($_GET['p']);




/**/
?>